home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: Easiest way to center a string?
- Date: 21 Feb 1996 15:26:44 GMT
- Organization: Los Alamos National Laboratory
- Distribution: world
- Message-ID: <TANMOY.96Feb21082644@qcd.lanl.gov>
- References: <4fobka$1st@parlor.hiwaay.net> <DMqEG5.8z4@eskimo.com>
- <4frif5$e6p@fohnix.metronet.com> <DMuuzG.1yK@eskimo.com>
- <4gbmmo$m5v@airdmhor.gen.nz>
- <Pine.A32.3.91.960220105403.86291D-100000@red.weeg.uiowa.edu>
- <TANMOY.96Feb20163829@qcd.lanl.gov>
- <Pine.A32.3.91.960221001254.156335E-100000@black.weeg.uiowa.edu>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: The Amorphous Mass's message of Wed, 21 Feb 1996 00:17:44 -0600
-
- In article
- <Pine.A32.3.91.960221001254.156335E-100000@black.weeg.uiowa.edu> The
- Amorphous Mass <robinson@blue.weeg.uiowa.edu> writes:
- <snip>
- > In article Amorphous Mass <robinson@blue.weeg.uiowa.edu> writes:
- > <snip>
- > That's equivalent to strlen(String + -LineLen), which is in turn
- > equivalent to strlen(String[-LineLen]), and the expression String[-80] is
-
- ^ this is now a char, not a char*.
-
- > portable only in the sense that its behavior is undefined on all
- > platforms. :)
- >
- > Sorry there is no trigraph for `&': so if that key is broken, you just
- > have to get it fixed :-)
-
- ??? Works fine. My tilde key is broken though, which makes UNIX a real
- pain.
-
- >
- > If you meant (strlen(String) - LineLen) / 2 then you will get a
- > negative length specifier for any string with fewer than LineLen
- > characters. If you meant (LineLen - strlen(String) / 2, then your
- >
- > strlen returns size_t which is guaranteed unsigned. (I am assuming
- > LineLen is not long.)
-
- Right, but strlen(String) would be 12, minus LineLen which is 80, which
- is -68, divided by two is -34, which is the number passed as a width
-
- but if size_t is unsigned int or unsigned long, and LineLen is int,
- the result is not -68 because an unsigned quantity cannot be -68. (My
- parenthetical remark was wrong: I had assumed that size_t was at least
- as long as unsigned int and LineLen is not long).
-
- specifier to printf(). I don't think printf("%*s", -34, "hello, world);
- is worth much. :)
-
- Neither is the unsigned number that you get.
-
- By the way, I thought the * specifier needs an int, an unsigned int
- will not do.
-
- I guess I didn't say that at all clearly the first time. Is it clearer
- now, or am I _completely_ brain-dead?
-
- I was not clear either.
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-